using System.IO;
using System.Collections.Generic;
using dotnet;

namespace command
{
    public class CmdLine
    {
        public static Dictionary<string, Cmd> RegisteredCmds = new Dictionary<string, Cmd>(0);

        public static void RegisterCmd(Cmd cmd)
        {
            RegisteredCmds.Add(cmd.Command, cmd);
        }

        public static void Analysis(string[] args)
        {
            if (args.Length == 0)
            {
                RegisteredCmds["--help"].Function(null);
                return;
            }
            bool notmatch = true;
            foreach (var cmd in RegisteredCmds)
            {
                if (args[0].Equals(cmd.Key))
                {
                    notmatch = false;
                    if (cmd.Value.IsWorkAreaCmd && (cmd.Value.Data = Utils.GetTopCfgPath()) == null)
                    {
                        Utils.ErrorLog("Here is not a sync folder.");
                        break;
                    }
                    cmd.Value.Function(args);
                    break;
                }
            }
            if (notmatch)
            {
                RegisteredCmds["--help"].Function(null);
            }
        }
    }
}